#include<iostream>
using namespace std;
const int N = 20;
int st[N];
int used[N];
int n;
void dfs(int u)
{
	if (u > n) {
		for (int i = 1; i <= n; i++) {
			cout << st[i] << " ";
		}
		puts("");
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			st[u] = i;
			used[i] = 1;
			dfs(u + 1);
			st[u] = 0;
			used[i] = 0;
		}
	}
}
int main()
{
	cin >> n;
	dfs(1);
	return 0;
}